package graph;

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;

class Trie1 {

    private final LinkedHashSet<String> linkedHashSet = new LinkedHashSet<>();

    public Trie1() {

    }

    public void insert(String word) {
        linkedHashSet.add(word);
    }

    public boolean search(String word) {
        return linkedHashSet.contains(word);
    }

    public boolean startsWith(String prefix) {
        List<String> list = new ArrayList<>(linkedHashSet);
        if (list.isEmpty())
            return false;
        for (String s : list) {
            if (s.startsWith(prefix))
                return true;
        }
        return false;
    }
}